package com.byq.mm.application.cluster.server;

import java.util.ArrayList;
import java.util.Collection;


import com.byq.mm.abstractx.device.Device;
import com.byq.mm.abstractx.engine.CoreEnvironment;
import com.byq.mm.abstractx.protocol.Interaction;
import com.byq.mm.application.cluster.provider.LevelControlProvider;
import com.byq.mm.application.cluster.server.executor.LevelControlExecutor;

import com.byq.mm.cluster.provider.SimpleSensorProvider;
import com.byq.mm.foundation.cluster.datatype.AttributeValue;
import com.byq.mm.foundation.cluster.datatype.DoubleRangeValue;
import com.byq.mm.foundation.cluster.datatype.DoubleValue;
import com.byq.mm.foundation.cluster.datatype.StringValue;
import com.byq.mm.foundation.cluster.server.BasicClusterServer;

public class SimpleSensorServer extends BasicClusterServer{

	public SimpleSensorServer(String cluster, Device device, CoreEnvironment env) {
		super(cluster, device, env);
	}

	@Override
	public boolean onCommand(Interaction i, String transport) {
		return super.onCommand(i, transport);
		
		
		
	}
	public void onValueChange(DoubleValue value){
		attributes.put(SimpleSensorProvider.Define.Attributes.VALUE, value);
		this.broadcastAttributeToAll(SimpleSensorProvider.Define.Attributes.VALUE);
		
	}
	public void setRange(DoubleRangeValue range){
		attributes.put(SimpleSensorProvider.Define.Attributes.RANGE, range);
		
		
	}
	public void setUnit(StringValue unit){
		attributes.put(SimpleSensorProvider.Define.Attributes.UNIT, unit);
	}
	@Override
	protected Class<? extends AttributeValue> getAttributeType(String attributeName) {
		if(attributeName.equals(SimpleSensorProvider.Define.Attributes.VALUE))
			return DoubleValue.class;
		if(attributeName.equals(SimpleSensorProvider.Define.Attributes.RANGE))
			return DoubleRangeValue.class;
		return null;
	}

	@Override
	protected void init() {
		attributes.put(SimpleSensorProvider.Define.Attributes.VALUE,new DoubleValue(0));
		
		attributes.put(SimpleSensorProvider.Define.Attributes.RANGE,  new DoubleRangeValue(0,100));
		
		attributes.put(SimpleSensorProvider.Define.Attributes.UNIT,  new StringValue("unkown"));
		subscriber.put(SimpleSensorProvider.Define.Attributes.VALUE,  new ArrayList<String>());
		
	}


}
